package network.rpc;


import network.rpc.client.RpcClient;
import network.rpc.server.ServiceCenter;
import network.rpc.server.ServiceCenterImpl;
import network.rpc.service.HelloService;
import network.rpc.service.HelloServiceImpl;



import java.io.IOException;
import java.net.InetSocketAddress;

public class RPCTest {
    public static void main(String[] args) {
        ServiceCenter serviceCenter = new ServiceCenterImpl(8050);
        serviceCenter.register(HelloService.class, HelloServiceImpl.class);
        new Thread(() -> {
            try {
                serviceCenter.start(); // 启动服务
            } catch (IOException e) {
                e.printStackTrace();
            }
        }).start();


        RpcClient rpcClient = new RpcClient();
        HelloService helloServiceProxy = (HelloService) rpcClient.getRemoteServiceProxy(
                HelloService.class,
                new InetSocketAddress("localhost", serviceCenter.getPort())
        );
        System.out.println(helloServiceProxy.getHello("Beney"));
    }
}
